package main.java.com.config;

import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.kit.PropKit;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.c3p0.C3p0Plugin;
import main.java.com.controller.IndexController;
import main.java.com.model.UserModel;


public class NeteaseConfig extends JFinalConfig {
		/**
		 * 配置常量
		 */
		public void configConstant(Constants me) {
			// 加载少量必要配置，随后可用PropKit.get(...)获取值
			PropKit.use("config.properties");
			me.setDevMode(PropKit.getBoolean("devMode", false));
		}
		/**
		 * 配置路由
		 */
		public void configRoute(Routes me) {
			me.add("/", IndexController.class);	// 第三个参数为该Controller的视图存放路径
		}

		
		public static C3p0Plugin createC3p0Plugin() {
			return new C3p0Plugin(PropKit.get("jdbcUrl"), PropKit.get("user"), PropKit.get("password").trim());
		}
		@Override
		public void configPlugin(Plugins me) {
			// 配置C3p0数据库连接池插件
			C3p0Plugin C3p0Plugin = createC3p0Plugin();
			me.add(C3p0Plugin);
			
			// 配置ActiveRecord插件
			ActiveRecordPlugin arp = new ActiveRecordPlugin(C3p0Plugin);
			me.add(arp);
			
			arp.addMapping("t_user","user_id",UserModel.class);
		}
		
		@Override
		public void configInterceptor(Interceptors me) {
			// TODO Auto-generated method stub

		}

		@Override
		public void configHandler(Handlers me) {
			// TODO Auto-generated method stub
//			me.add(new ContextPathHandler("basePath"));
			
		}
}
